package com.weme.common.activity

import android.os.Bundle
import android.webkit.WebSettings
import android.webkit.WebViewClient
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.weme.common.base.BaseMvvmActivity
import com.weme.common.base.BaseViewModel
import com.weme.common.databinding.ActivityWebviewBinding

class WebViewActivity : BaseMvvmActivity<ActivityWebviewBinding, BaseViewModel>() {
    override fun initView(savedInstanceState: Bundle?) {
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).titleBar(mBinding.customTopNavigationBar).init()
        initWebViewSettings()
    }

    private fun initWebViewSettings() {

     //   intent.getStringExtra("url")?.let { mBinding.webView.loadUrl(it) }
        val settings: WebSettings = mBinding.webView.settings

        // 启用 JavaScript
        settings.javaScriptEnabled = true

        // 禁用缩放
        settings.setSupportZoom(false)
        settings.builtInZoomControls = false
        settings.displayZoomControls = false

        // 在 WebView 中打开链接，而不是跳转到浏览器
        val webViewClient = WebViewClient()
        webViewClient.onLoadResource(mBinding.webView,intent.getStringExtra("url"))

//        // 获取页面标题
//        var webChromeClient = object : WebChromeClient() {
//            override fun onReceivedTitle(view: WebView?, title: String?) {
//                super.onReceivedTitle(view, title)
//                mBinding.customTopNavigationBar.setTitle(title.toString())
//            }
//        }
    }


    override fun getViewModelClass(): Class<BaseViewModel> = BaseViewModel::class.java

    
}